import axios from 'axios'
import { Loading,Message } from 'element-ui';

// Loading.service(document.body);  //启动loading
let loadingInstance = null;
export function request(config){
    
    const instance=axios.create({
            baseURL:"https://cnodejs.org/api/v1",
            timeout:5000
        });
      //请求拦截
    instance.interceptors.request.use(config=>{
      console.log('请求拦截');  
      loadingInstance=Loading.service(document.body);
        return config;
      },err=>{  
        Message.error({message: '请求超时!'});
        console.log('请求失败');   
      })
        
    // 响应拦截
    instance.interceptors.response.use(config=>{
      console.log('响应拦截'); 
      Message.success({message: '数据更新成功'});
      loadingInstance.close();
          return config;
      },err=>{  
        console.log('响应失败');
        Message.error({message: '数据获取失败'});
              })  

      return instance(config);      
    
}